import {BizError} from '../exception/exceptions'
import api from './impl/axios_api_instance'
import {Toast} from 'vant'
import store from '@/repo/store/store'
import rest from './rest'

export default function postApiNewUnLogged (data) {
  if (!data) {
    console.error('post api data cannot be null')
    return
  }
  data.requestData = data.requestData || {}
  data.requestData.timestamp = new Date().getTime()
  data.userid = '0'
  data.tsId = data.tsId || store.getters.hsId
  return postNewUnLogged(`${rest.apiHost}/mobile/apisFlux`, [data]).then(result => {
      let response = result[0] || {}
      let resultCode = response.hasOwnProperty('resultCode') ? response.resultCode : -1
      if (resultCode === 0) {
        return Promise.resolve(response)
      }
      Toast(response.resultInfo)
      return Promise.reject(new BizError(result))
    }
  )
}

function postNewUnLogged (url, data) {
  return api.postNewUnLogged(url, data).then(res => res.data || [])
}

